﻿using System;
using System.Windows;
using PairingMatrix.Common.Command;
using PairingMatrix.Common.Enum;
using PairingMatrix.Model;

namespace PairingMatrix.ViewModel
{
    public class PairedWithViewModel : ViewModelBase, IPairedWithViewModel, IComparable<PairedWithViewModel>
    {
        private readonly PairedWithModel _model;
        public PairedWithViewModel(PairedWithModel model)
        {
            _model = model;
        }

        public ITeamMemberCardViewModel Member
        {
            get { return new TeamMemberCardViewModel(_model.Member); }
        }

        public int NumberOfTimesPaired
        {
            get { return _model.NumberOfTimesPaired; }
        }

        public PairingLevel PairingLevel
        {
            get { return _model.PairingLevel; }
        }

        private Point _position;
        public Point Position
        {
            get { return _position; }
            set
            {
                if(_position == value)
                    return;
                _position = value;
                OnPropertyChanged("Position");
            }
        }

        public PairedWithModel Model
        {
            get { return _model; }
        }

        private RelayCommand _incrementPairing;
        public RelayCommand IncrementPairing
        {
            get
            {
                if (_incrementPairing == null)
                    _incrementPairing = new RelayCommand(param => _model.IncrementPairing());
                return _incrementPairing;
            }
        }


        public int CompareTo(PairedWithViewModel other)
        {
            if (other.NumberOfTimesPaired > NumberOfTimesPaired)
                return -1;
            if (other.NumberOfTimesPaired < NumberOfTimesPaired)
                return 1;
            return 0;
        }
    }
}